home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / X11 / xmbase-grok-1.2 / popup.c < prev    next >
C/C++ Source or Header  |  1995-06-25  |  7KB  |  232 lines

  1. /*
  2.  * Various popups, such as the About... dialog.
  3.  *
  4.  *    create_about_popup()
  5.  *                    Create About info popup
  6.  *    create_error_popup(widget, error, fmt, ...)
  7.  *                    Create error popup with Unix error
  8.  */
  9.  
  10. #include "config.h"
  11. #include <stdarg.h>
  12. #include <stdio.h>
  13. #include <time.h>
  14. #include <X11/Xos.h>
  15. #include <errno.h>
  16. #include <Xm/Xm.h>
  17. #include <Xm/MessageB.h>
  18. #include <Xm/Protocols.h>
  19. #include "grok.h"
  20. #include "form.h"
  21. #include "proto.h"
  22. #include "patchlevel.h"
  23.  
  24. #ifndef __DATE__
  25. #define __DATE__ ""
  26. #endif
  27.  
  28. extern char        *progname;    /* argv[0] */
  29. extern Display        *display;    /* everybody uses the same server */
  30. extern Widget        mainwindow;    /* popup menus hang off main window */
  31. extern struct        pref pref;    /* global preferences */
  32.  
  33.  
  34. /*---------------------------------------------------------- about ----------*/
  35. /*
  36.  * install the About popup. Nothing can be done with it except clicking it
  37.  * away. This is called from the File pulldown in the main menu.
  38.  */
  39.  
  40. static char about_message[] = "\
  41. \n\
  42. Graphical Resource Organizer Kit\n\
  43. Version %s\n\
  44. Compiled %s\n\n\
  45. Author: Thomas Driemeyer\n\
  46. thomas@bitrot.in-berlin.de\
  47. \n";
  48.  
  49. void create_about_popup(void)
  50. {
  51.     char            msg[512];
  52.     Widget            dialog;
  53.     XmString        s;
  54.     Arg            args[10];
  55.     int            n;
  56.  
  57.     sprintf(msg, about_message, VERSION, __DATE__);
  58.     s = XmStringCreateLtoR(msg, XmSTRING_DEFAULT_CHARSET);
  59.     n = 0;
  60.     XtSetArg(args[n], XmNmessageString, s); n++;
  61.     dialog = XmCreateInformationDialog(mainwindow, "About", args, n);
  62.     XmStringFree(s);
  63.     XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_HELP_BUTTON));
  64.     XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_CANCEL_BUTTON));
  65.     (void)XmInternAtom(display, "WM_DELETE_WINDOW", False);
  66.     XtManageChild(dialog);
  67. }
  68.  
  69.  
  70. /*---------------------------------------------------------- errors ---------*/
  71. /*
  72.  * install an error popup with a message. If a nonzero error is given,
  73.  * insert the appropriate Unix error message. The user must click this
  74.  * away. The widget is some window that the popup goes on top of.
  75.  */
  76.  
  77. extern char *sys_errlist[];    /* hpux9.01 errno.h is broken! */
  78.  
  79. /*VARARGS*/
  80. void create_error_popup(Widget widget, int error, char *fmt, ...)
  81. {
  82.     va_list            parm;
  83.     char            msg[17108];
  84.     Widget            dialog;
  85.     XmString        string;
  86.     Arg            args;
  87.  
  88.     strcpy(msg, "ERROR:\n\n");
  89.     va_start(parm, fmt);
  90.     vsprintf(msg + strlen(msg), fmt, parm);
  91.     va_end(parm);
  92.     if (error) {
  93.         strcat(msg, "\n");
  94.         strcat(msg, sys_errlist[error]);
  95.     }
  96.     string = XmStringCreateLtoR(msg, XmSTRING_DEFAULT_CHARSET);
  97.     XtSetArg(args, XmNmessageString, string);
  98.     dialog = XmCreateWarningDialog(widget, "Grok Error", &args, 1);
  99.     XmStringFree(string);
  100.     XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_CANCEL_BUTTON));
  101.     XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_HELP_BUTTON));
  102.     (void)XmInternAtom(display, "WM_DELETE_WINDOW", False);
  103.     XtManageChild(dialog);
  104. }
  105.  
  106.  
  107. /*---------------------------------------------------------- question -------*/
  108. /*
  109.  * put up a dialog with a message, and wait for the user to press either
  110.  * the OK or the Cancel button. When the OK button is pressed, call the
  111.  * callback. If Cancel is pressed, the callback is not called. The widget
  112.  * is some window that the popup goes on top of. The help message is some
  113.  * string that appears in grok.hlp after %%.
  114.  */
  115.  
  116. /*VARARGS*/
  117. void create_query_popup(
  118.     Widget        widget,            /* window that caused this */
  119.     void        (*callback)(),        /* OK callback */
  120.     char        *help,            /* help text tag for popup */
  121.     char        *fmt, ...)        /* message */
  122. {
  123.     va_list        parm;
  124.     char        msg[1024];
  125.     Widget        dialog;
  126.     XmString    string;
  127.     Arg        args[2];
  128.  
  129.     va_start(parm, fmt);
  130.     vsprintf(msg, fmt, parm);
  131.     va_end(parm);
  132.     string = XmStringCreateLtoR(msg, XmSTRING_DEFAULT_CHARSET);
  133.  
  134.     XtSetArg(args[0], XmNmessageString,     string);
  135.     XtSetArg(args[1], XmNdefaultButtonType, XmDIALOG_CANCEL_BUTTON);
  136.     dialog = XmCreateQuestionDialog(widget, "Grok Dialog", args, 2);
  137.     XmStringFree(string);
  138.  
  139.     XtAddCallback(dialog, XmNokCallback,
  140.             (XtCallbackProc)callback, NULL);
  141.     XtAddCallback(dialog, XmNhelpCallback,
  142.             (XtCallbackProc)help_callback, (XtPointer)help);
  143.     XtSetSensitive(XmMessageBoxGetChild(dialog,
  144.                         XmDIALOG_HELP_BUTTON), !!help);
  145.     (void)XmInternAtom(display, "WM_DELETE_WINDOW", False);
  146.     XtManageChild(dialog);
  147. }
  148.  
  149.  
  150. /*---------------------------------------------------------- dbase info -----*/
  151. /*
  152.  * install the Database info popup. It displays useful information about
  153.  * the named card. This is called from the Help pulldown in the main menu.
  154.  */
  155.  
  156. static char info_message[] = "\n\
  157.   Form name:  %s\n\
  158.   Form path:  %s\n\
  159.   Form comment:  %s\n\n\
  160.   Default query:  %s\n\n\
  161.   Database name:  %s%s%s\n\
  162.   Database size:  %d cards,  %d columns\n\n\
  163.   Help information:\n%s\n\n\
  164.   Sections:\
  165. ";
  166.  
  167. void create_dbase_info_popup(
  168.     CARD        *card)
  169. {
  170.     FORM        *form;
  171.     DBASE        *dbase;
  172.     char        msg[8192], date[20];
  173.     struct tm    *tm;
  174.     Widget        dialog;
  175.     XmString    s;
  176.     Arg        args[10];
  177.     int        n;
  178.  
  179.     if (!card)
  180.         return;
  181.     form  = card->form;
  182.     dbase = card->dbase;
  183.     sprintf(msg, info_message,
  184.         form && form->name    ? form->name          : "(none)",
  185.         form && form->path    ? form->path          : "(none)",
  186.         form && form->comment    ? form->comment          : "(none)",
  187.         form && form->autoquery >= 0
  188.                     ? form->query[form->autoquery].name
  189.                     : "(none)",
  190.         form  && form->dbase    ? form->dbase          : "(none)",
  191.         dbase && dbase->rdonly ||
  192.         form  && form->rdonly    ? " (read-only)"      : "",
  193.         form  && form->proc    ? " (procedural)"     : "",
  194.         dbase            ? dbase->nrows          : 0,
  195.         dbase            ? dbase->maxcolumns-1 : 0,
  196.         form  && form->help    ? form->help          : "     (none)");
  197.     if (!dbase || !dbase->nsects)
  198.         strcat(msg, " (none)");
  199.     else {
  200.         register SECTION *sect = dbase->sect;
  201.         for (n=0; n < dbase->nsects; n++, sect++) {
  202.             tm = localtime(§->mtime);
  203.             if (pref.mmddyy)
  204.                 sprintf(date, "%2d/%02d/", tm->tm_mon+1,
  205.                                tm->tm_mday);
  206.             else
  207.                 sprintf(date, "%2d.%02d.", tm->tm_mday,
  208.                                tm->tm_mon+1);
  209.             sprintf(date+6, "%2d %2d:%02d",    tm->tm_year % 100,
  210.                                tm->tm_hour,
  211.                                tm->tm_min);
  212.             sprintf(msg + strlen(msg),
  213.                 "\n      %s:  %d cards, %s, \"%s\" %s%s",
  214.                 section_name(dbase, n),
  215.                 sect->nrows == -1 ? 0 : sect->nrows,
  216.                 date,
  217.                 sect->path,
  218.                 sect->rdonly   ? " (read only)" : "",
  219.                 sect->modified ? " (modified)"  : "");
  220.         }
  221.     }
  222.     s = XmStringCreateLtoR(msg, XmSTRING_DEFAULT_CHARSET);
  223.     n = 0;
  224.     XtSetArg(args[n], XmNmessageString, s); n++;
  225.     dialog = XmCreateInformationDialog(mainwindow, "Database Info", args,n);
  226.     XmStringFree(s);
  227.     XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_HELP_BUTTON));
  228.     XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_CANCEL_BUTTON));
  229.     (void)XmInternAtom(display, "WM_DELETE_WINDOW", False);
  230.     XtManageChild(dialog);
  231. }
  232.